// goodList.js
var app = getApp()
Page({

  data: {
  },
  onLoad: function (options) {
    var thiz = this

    var domain = app.globalData.domain
    var goodsListUrl = app.globalData.goodsListInterface
    var kui_key = app.globalData.kui_key
    var cid = app.globalData.cid
    var user_id = app.globalData.inv_i

    var goodsList = domain + goodsListUrl

    wx.request({
      url: goodsList,
      method: 'post',
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      data: {
        c_id: cid,
        kui_key: kui_key,
        key: options.key ? options.key : "",
        id: options.id ? options.id : "",
        model: "MINI",
        user_id: user_id
      },
      success: function (res) {
        if (res.data.length > 0) {
          var goodsList = []
          if (options.type == 'is_hot' && options.type) {
            res.data.forEach(function (element, index) {
              if (element.is_hot == '1') {
                goodsList.push(element)
              }
              element.default_img = domain + "/" + element.default_img
            })
          } else {
            res.data.forEach(function (element, index) {
              element.default_img = domain + "/" + element.default_img
            })
            goodsList = res.data
          }


          thiz.setData({
            hiddenLoading: true,
            goodsList: goodsList
          })
        } else {

          thiz.setData({
            hiddenLoading: true,
            errMsg: '商家没有添加商品数据'
          })
        }
      }
    })

    var thiz = this;
    wx.getSystemInfo({
      success: function (res) {
        thiz.setData({
          hiddenLoading: true,
          windowHeight: res.windowHeight,
          windowWidth: res.windowWidth
        });
      }
    })
  },
  //商品点击进入商品详情页面
  goodsClick: function (e) {
    var id = e.currentTarget.dataset.id;

    wx.navigateTo({
      url: '../goodsDetail/goodsDetail?goods_id= ' + id,
    })
  },
  showInput: function () {
    this.setData({
      inputShowed: true
    });
  },
  hideInput: function () {
    this.setData({
      inputVal: "",
      inputShowed: false
    });
  },
  clearInput: function () {
    this.setData({
      inputVal: ""
    });
  },
  inputTyping: function (e) {
    this.setData({
      inputVal: e.detail.value
    });
  }
})